<?php

namespace App\Admin\Actions\Grid\Row\SwtBjMachine;

use App\Admin\Logic\Ty\TyMachineLogic;
use App\Services\BaoJianService;
use Dcat\Admin\Actions\Response;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Traits\HasPermissions;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class MachineRestart extends RowAction
{
    /**
     * @return string
     */
    protected $title = '重启';

    /**
     * Handle the action request.
     *
     * @param Request $request
     *
     * @return Response
     */
    public function handle(Request $request)
    {
        $params = $request->all();

        BaoJianService::machineRestart($params['device_code']);

        return $this->response()
            ->success('操作成功')
            ->refresh();
    }

    /**
     * @return string|array|void
     */
    public function confirm()
    {
        return ['确认操作吗?', '设备将重新启动'];
    }

    /**
     * @param Model|Authenticatable|HasPermissions|null $user
     *
     * @return bool
     */
    protected function authorize($user): bool
    {
        return true;
    }

    /**
     * @return array
     */
    protected function parameters()
    {
        return [
            'device_code'  => $this->row->device_code,
        ];
    }

    protected function html()
    {
        return <<<HTML
            <a {$this->formatHtmlAttributes()}><i class="feather icon-refresh-cw text-info"></i> <span class="text-info">{$this->title}</span> &emsp;</a>
        HTML;
    }
}
